//
//  MainNavigationController.swift
//  Swift_Weibo
//
//  Created by Tim on 2019/8/13.
//  Copyright © 2019 Tim. All rights reserved.
//  全局 navigation controller

import UIKit

class MainNavigationController: UINavigationController {
    override func viewDidLoad() {
        super.viewDidLoad()
        navigationBar.isHidden = true
    }
    
    override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        if children.count > 0 {
            viewController.hidesBottomBarWhenPushed = true
            
            if let vc = viewController as? WBBaseViewController {
                var backText = "返回"
                if children.count == 1 {
                    backText = children.first?.title ?? "返回"
                }
                
                vc.navItem.leftBarButtonItem = UIBarButtonItem(title: backText, target: self, action: #selector(popToParent), isBack: true)
            }
        }
        
        super.pushViewController(viewController, animated: true)
    }
    
    @objc func popToParent() {
        popViewController(animated: true)
    }
}

